home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCsiod / SIOD / Small-Siod.scm < prev    next >
Text File  |  1993-09-24  |  4KB  |  135 lines

  1. ; Scheme In One Define.
  2. ; The garbage collector, the name and other parts of this program are
  3. ;
  4. ; *                     COPYRIGHT (c) 1989 BY                              *
  5. ; *      PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.       *
  6. ;
  7. ; Conversion  to  full scheme standard, characters, vectors, ports, complex &
  8. ; rational numbers, debug utils, and other major enhancments by
  9. ;
  10. ; *      Scaglione Ermanno, v. Pirinoli 16 IMPERIA P.M. 18100 ITALY        * 
  11. ;
  12. ; Permission  to use, copy, modify, distribute and sell this software and its
  13. ; documentation  for  any purpose and without fee is hereby granted, provided
  14. ; that  the  above  copyright  notice appear in all copies and that both that
  15. ; copyright   notice   and   this  permission  notice  appear  in  supporting
  16. ; documentation,  and that the name of Paradigm Associates Inc not be used in
  17. ; advertising or publicity pertaining to distribution of the software without
  18. ; specific, written prior permission.
  19. ;
  20. ; Small runtime library for version 2.6
  21.  
  22.  
  23. (define (caar x) (cxr x "aa"))
  24. (define (cadr x) (cxr x "da"))
  25. (define (cdar x) (cxr x "ad"))
  26. (define (cddr x) (cxr x "dd"))
  27.  
  28. (define (caaar x) (cxr x "aaa"))
  29. (define (caadr x) (cxr x "daa"))
  30. (define (cadar x) (cxr x "ada"))
  31. (define (caddr x) (cxr x "dda"))
  32.  
  33. (define (cdaar x) (cxr x "aad"))
  34. (define (cdadr x) (cxr x "dad"))
  35. (define (cddar x) (cxr x "add"))
  36. (define (cdddr x) (cxr x "ddd"))
  37.  
  38. (macro delay (lambda (x)
  39.                  `(cons #f
  40.                        (lambda () ,(cadr x)))))
  41.  
  42. (define (force x) 
  43.         (if (car x)
  44.             (cdr x) 
  45.             (begin (set-cdr! x ((cdr x)))
  46.                    (set-car! x #t)
  47.                    (cdr x))))
  48. (macro cons-stream 
  49.        (lambda (x)
  50.                `(cons ,(cadr x)
  51.                       (delay ,(caddr x)))))
  52.  
  53. (define head car)
  54.  
  55. (define (tail x) (force (cdr x)))
  56.  
  57. (define the-empty-stream 'the-empty-stream)
  58.  
  59. (define (empty-stream? x) (eq? x 'the-empty-stream))
  60.  
  61. (define (stream->list z)
  62.         (if (empty-stream? z)
  63.             '()
  64.             (cons (head z) (stream->list (tail z)))))
  65.  
  66. (define (list->stream z)
  67.         (if (null? z)
  68.             the-empty-stream
  69.             (cons-stream (car z) (list->stream (cdr z)))))
  70.  
  71. (define (open-input-file x) (open-port x "r" 1))
  72.  
  73. (define (open-output-file x) (open-port x "w" 1))
  74.  
  75. (define (newline . x) (display #\newline (car x)))
  76.  
  77. (define (page . x) (display #\page (car x)))
  78.  
  79. (define (string<? x y)
  80.         (< (string-cmp x y) 0))        
  81.  
  82. (define (string>? x y)
  83.         (> (string-cmp x y) 0))
  84.  
  85. (define (string=? x y)
  86.         (= (string-cmp x y) 0))
  87.  
  88. (define (string<=? x y)
  89.         (<= (string-cmp x y) 0))
  90.  
  91. (define (string>=? x y)
  92.         (>= (string-cmp x y) 0))
  93.  
  94. (define (substring<? x y z a b c)
  95.         (string<? (substring x y z) (substring a b c)))
  96.  
  97. (define (substring=? x y z a b c)
  98.         (string=? (substring x y z) (substring a b c)))
  99.  
  100. (define (substring-fill! x y z a)
  101.         (while (< y z)
  102.                (string-set! x y a)
  103.                (set! y (1+ y)))
  104.         x)
  105.  
  106. (define (char<? x y)
  107.         (< (char-cmp x y) 0))   
  108.      
  109. (define (char>? x y)
  110.         (> (char-cmp x y) 0))
  111.                    
  112. (define (char=? x y)
  113.         (= (char-cmp x y) 0))
  114.  
  115. (define (char<=? x y)
  116.         (<= (char-cmp x y) 0))
  117.  
  118. (define (char>=? x y)
  119.         (>= (char-cmp x y) 0))
  120.  
  121. (define #\newline (integer->char 10))
  122.  
  123. (define #\page (integer->char 12))
  124.  
  125. (define #\space (integer->char 32))
  126.  
  127. (macro make-environment (lambda (x)
  128.                                 `(let () 
  129.                                       ,@(cdr x) 
  130.                                       (the-environment))))
  131.  
  132. (define (ced)
  133.         (dos-call "ced"))
  134.